@extends('layouts.tankuang')

@section('content')
    <div id="faren">
        <a class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="add_anjian()">新增</a>
        <a class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="edit_anjian()">编辑</a>
        <a class="easyui-linkbutton" iconCls="icon-cancel" plain="true" onclick="del_anjian()">删除</a>
    </div>
    <table id="faren_form" title="" class="easyui-datagrid table_h" style="width:100%;height:720px;"        data-options="rownumbers:true,singleSelect:true,pagination:true,pageSize:20,url:'http://nb.yntosite.com/json/anjian.json',method:'get',toolbar:'#faren'">
        <thead>
        <tr>
           <th data-options="field:'name'" width="20%" align="center">案件名称</th>
            <th data-options="field:'time'" width="10%" align="center">案发时间</th>
            <th data-options="field:'address'" width="10%" align="center">案发地点</th>
            <th data-options="field:'contact'" width="10%" align="center">联系人</th>
            <th data-options="field:'tel'" width="10%" align="center">联系方式</th>
            <th data-options="field:'status'" width="10%" align="center">案件类型</th>
            <th data-options="field:'information'" width="30%" align="center">案情描述</th>
        </tr>
        </thead>
    </table>

    <div id="tk" class="easyui-window" closed="true" title="新增" data-options="iconCls:'icon-save'"></div>

    <div id="del_faren" class="easyui-dialog" title="注销" closed="true" style="width:400px;height:200px;line-height:100px;text-align:center;font-size:16px;padding:10px">
        您确定要删除该记录？
    </div>
	<script type="text/javascript" src="{{ URL::asset('/') }}js/weizhi.js"></script>
    <script type="text/javascript">
        function add_anjian(){
        	var shuz = fb2();
            $('#tk').window({
                title: "添加",
                href: "add_anjian",
                width:shuz[0],
				height:shuz[1],
				top:shuz[2],
				left:shuz[3],
                minimizable:false,
                modal:true,
                closed: false,
            });
        }
        function edit_anjian(){
        	var shuz = fb2();
        	console.log(shuz);
            var row = $('#faren_form').datagrid('getSelected');
            if (row) {
                var url = "edit_anjian";
                $('#tk').window({
                    title: "编辑",
                    href: url,
                    width:shuz[0],
					height:shuz[1],
					top:shuz[2],
					left:shuz[3],
                    minimizable:false,
                    modal:true,
                    closed: false,
                });
            } else {
                $.messager.alert('提示','请选中要编辑的行！');
            }
        }
        function del_anjian(){
            var row = $('#faren_form').datagrid('getSelected');
            if (row) {
                $('#del_faren').dialog({
                    title: "删除",
                    closed: false,
                    top:($(window).height() - 200) * 0.5,
				    left:($(window).width() - 400) * 0.5,
                    modal:true,
                    buttons: [{
                        text: '确定',
                        iconCls: 'icon-ok',
                        handler: del
                    }, {
                        text: '取消',
                        iconCls: 'icon-cancel',
                        handler: function () {
                            $('#del_faren').dialog('close');
                        }
                    }]
                });
            } else {
                $.messager.alert('提示','请选中要编辑的行！');
            }
        }

        function del(){
            $('#del_faren').dialog('close');
            var row = $('#faren_form').datagrid('getSelected');
            var url = '/admin/yanpan/del_anjian/'+row.id;
            $.ajax({
                type: 'get',
                url: url,
                success: function(data){
                    if(data.status == 1){
                        $.messager.alert('信息提示',data.msg,'info');
                        var rowIndex = $('#faren_form').datagrid('getRowIndex', row);
                        $('#faren_form').datagrid('deleteRow', rowIndex);
                    }
                    else{
                        $.messager.alert('信息提示',data.msg,'info');
                    }
                }
            });
        }
        $("#faren_form").datagrid({
            onDblClickRow: function (index, row) {
                edit_anjian();
            }
        });
    </script>
@stop

